package com.cdn.dns.controller;

import com.cdn.common.core.web.controller.BaseController;
import com.cdn.common.core.web.domain.AjaxResult;
import com.cdn.common.core.web.page.TableDataInfo;
import com.cdn.common.log.annotation.Log;
import com.cdn.common.log.enums.BusinessType;
import com.cdn.common.security.annotation.RequiresPermissions;
import com.cdn.dns.domain.EdgeDnsProviders;
import com.cdn.dns.domain.dto.EdgeDnsApiAccountDTO;
import com.cdn.dns.domain.vo.EdgeDnsProvidersVO;
import com.cdn.dns.service.IEdgeDnsProvidersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * DNS服务商，用于记录DNS解析服务商的信息Controller
 * 
 * @author Cinzia
 * @date 2024-12-16
 */
@RestController
@RequestMapping("/providers")
public class EdgeDnsProvidersController extends BaseController
{
    @Autowired
    private IEdgeDnsProvidersService edgeDnsProvidersService;

    /**
     * 查询DNS服务商，用于记录DNS解析服务商的信息列表
     */
    @RequiresPermissions("dns:providers:list")
    @GetMapping("/list")
    public TableDataInfo list(EdgeDnsProviders edgeDnsProviders)
    {
        startPage();
        List<EdgeDnsProvidersVO> list = edgeDnsProvidersService.selectEdgeDnsProvidersList(edgeDnsProviders);
        return getDataTable(list);
    }

    /**
     * 获取DNS服务商，用于记录DNS解析服务商的信息详细信息
     */
    @RequiresPermissions("dns:providers:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(edgeDnsProvidersService.selectEdgeDnsProvidersById(id));
    }

    /**
     * 新增DNS服务商，用于记录DNS解析服务商的信息
     */
    @RequiresPermissions("dns:providers:add")
    @Log(title = "DNS服务商，用于记录DNS解析服务商的信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EdgeDnsProviders edgeDnsProviders)
    {
        return toAjax(edgeDnsProvidersService.insertEdgeDnsProviders(edgeDnsProviders));
    }

    /**
     * 修改DNS服务商，用于记录DNS解析服务商的信息
     */
    @RequiresPermissions("dns:providers:edit")
    @Log(title = "DNS服务商，用于记录DNS解析服务商的信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EdgeDnsProviders edgeDnsProviders)
    {
        return toAjax(edgeDnsProvidersService.updateEdgeDnsProviders(edgeDnsProviders));
    }

    /**
     * 删除DNS服务商，用于记录DNS解析服务商的信息
     */
    @RequiresPermissions("dns:providers:remove")
    @Log(title = "DNS服务商，用于记录DNS解析服务商的信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(edgeDnsProvidersService.deleteEdgeDnsProvidersByIds(ids));
    }

    /**
     * 获取DNS服务商管理的域名
     */
    @PostMapping("/getDnsInfoByAccount")
    public AjaxResult getDnsInfoByAccount(@RequestBody EdgeDnsApiAccountDTO edgeDnsApiAccountDTO)
    {
        return success(edgeDnsProvidersService.getDnsInfoByAccount(edgeDnsApiAccountDTO));
    }

    /**
     * 根据服务商获取服务商下的所有账号
     */
    @GetMapping("/getProvidersAccountList/{providerType}")
    public AjaxResult getProvidersAccountList(@PathVariable Integer providerType)
    {
        return success(edgeDnsProvidersService.getProvidersAccountList(providerType));
    }

    /**
     * 集群和服务商账号关联
     */
    @PostMapping("/clusterBindProviders/{clusterId}/{providersId}")
    public AjaxResult clusterBindProviders(@PathVariable Long clusterId,@PathVariable Long providersId){
        return success(edgeDnsProvidersService.clusterBindProviders(clusterId,providersId));
    }

    /**
     * 删除集群和服务商账号关联
     */
    @PostMapping("/delClusterBindProviders/{clusterId}")
    public AjaxResult delClusterBindProviders(@PathVariable Long[] clusterId){
        return success(edgeDnsProvidersService.delClusterBindProviders(clusterId));
    }

}
